<template>
	<view class="container">
		<!-- 儲值卡 -->
		<view class="nav">
			<view class="nav_list" :class="{active:status==0}" @tap="setStatus" data-status="0">未使用</view>
			<view class="nav_list" :class="{active:status==1}" @tap="setStatus" data-status="1">已使用</view>
			<view class="nav_list" :class="{active:status==2}" @tap="setStatus" data-status="2">已過期</view>
		</view>
		<view class="card_list">
			<scroll-view v-if="cardList.length" scroll-y="true" class="scroll_y" @scrolltolower="scroll">
				<view class="card_item" v-for="item in cardList" :key="item.id">
					<view class="left">
						<text>{{item.store_name}}</text>
						<text style="margin-top: 30rpx;">{{item.title}}</text>
					</view>
					<text>${{item.remaining_money}}</text>
					
				<!-- 	<view class="top">
						<text>{{item.title}}</text>
						<text>有效期至{{effectiveTime(item.expire_time*1000)}}</text>
					</view>
					<view class="available">實際金額<text
							style="color: #FA533D;margin-left: 15rpx;">${{item.remaining_money}}</text></view>
					<view class="buy">購買金額<text style="font-weight: bold;margin-left: 15rpx;">${{item.money}}</text>
					</view> -->

				</view>
				<view style="text-align: center;margin: 30rpx;" v-if="!flag">到底啦~</view>
			</scroll-view>
			<view style="text-align: center;" v-else>暫無儲值卡</view>
		</view>
	</view>
</template>

<script>
	import {
		getCouponTicketCard
	} from '@/api/me.js'
	export default {
		data() {
			return {
				status: 0,
				page: 1,
				type: 3, // 1--優惠卷   2--電子票卷   3--儲值卡
				cardList: [],
				flag: true
			};
		},
		methods: {
			setStatus: function(e) {
				// console.log(e.currentTarget.dataset.status)
				var status = e.currentTarget.dataset.status
				if (this.status != status) {
					this.status = status
				}
			},
			scroll() {
				if (this.flag) {
					getCouponTicketCard({
						type: this.type,
						status: this.status,
						page: ++this.page
					}).then(res => {
						// console.log(res.data, "儲值卡")
						if (res.data.length) {
							this.cardList = this.cardList.concat(res.data)
						} else {
							this.flag = false
						}
						// this.cardList = res.data
					})
				}
			},
			effectiveTime(num) {
				let time = new Date(num)
				let y = time.getFullYear()
				let m = time.getMonth() + 1 >= 10 ? time.getMonth() + 1 : "0" + (time.getMonth() + 1)
				let d = time.getDate() >= 10 ? time.getDate() : "0" + (time.getDate())
				return y + "/" + m + "/" + d
			},
		},
		watch: {
			status(n) {
				getCouponTicketCard({
					type: this.type,
					status: n,
					page: 1
				}).then(res => {
					console.log(res.data, "儲值卡")
					this.cardList = res.data
				})
			}
		},
		onShow() {
			getCouponTicketCard({
				type: this.type,
				status: this.status,
				page: this.page
			}).then(res => {
				console.log(res.data, "儲值卡")
				this.cardList = res.data
			})
		}
	}
</script>

<style lang="less">
	.container {
		padding: 15rpx 30rpx;
		box-sizing: border-box;
		height: calc(100vh - 90rpx);
		background: #F3F5F9;

		.nav {
			padding: 30rpx 37rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;

			.nav_list {
				font-size: 28rpx;
				color: #000;
				font-weight: 400;
			}

			.active {
				position: relative;
				font-weight: bold;

				&::after {
					content: "";
					display: block;
					position: absolute;
					left: 0%;
					bottom: 0%;
					width: 100%;
					height: 10rpx;
					background: #39B19D;
					border-radius: 5rpx 5rpx 5rpx 5rpx;
					opacity: 0.7;
					margin-top: 5rpx;
				}
			}
		}

		.card_list {
			margin-top: 31rpx;

			.card_item {
				width: 690rpx;
				height: 244rpx;
				background: linear-gradient(180deg, rgba(40, 193, 112, 0.82) 0%, rgba(38, 183, 106, 0.77) 56%, rgba(40, 193, 103, 0.41) 100%, rgba(20, 97, 56, 0.32) 100%);
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				opacity: 1;
				color: #fff;

				padding: 36rpx 43rpx 46rpx 32rpx;
				box-sizing: border-box;
				color: #fff;
				font-size: 48rpx;
				font-weight: bold;
				display: flex;
				justify-content: space-between;
				align-items: center;

				margin-bottom: 34rpx;

				padding: 20rpx;
				box-sizing: border-box;

				// .left,
				// .right {
				// 	display: flex;
				// 	flex-direction: column;
				// }

				// .top {
				// 	display: flex;
				// 	justify-content: space-between;
				// }

				// .available {
				// 	margin: 30rpx 0;
				// 	font-size: 40rpx;
				// 	font-weight: bold;
				// }

				// .buy {
				// 	text-align: end;
				// }

				.left {
					display: flex;
					flex-direction: column;
				}
			}

			.scroll_y {
				height: 85vh;
				// background-color: skyblue;
			}
		}
	}
</style>